<?php
namespace App\Http\Controllers\Store;

use App\Exceptions\ApiException;
use App\Http\Controllers\Controller;
use App\Exceptions\NotLoginException;
use App\Models\ShopStore;
use App\Models\ShopStoreRoles;
use App\Models\ClientUserTicket;
use Illuminate\Support\Facades\DB;
/**
 * Class CommonController
 * @package App\Http\Controllers\Company
 *
 * 商家版 API 接口部分
 */
class CommonController extends Controller {
	protected $user = [];
	protected $uid;
	protected $store_id;
	protected $store;
	// 商家需要全局登录
	public function __construct(){
		$this->check_login();
	}
	
	public function check_login(){
		$clientUserTicket = new ClientUserTicket();
		$user = $clientUserTicket->checkLogin();
		if($user->type != 4){
			throw new ApiException('用户角色错误，拒绝登录');
		}
		$this->user = $user;
		$this->uid = $user->id;
		$store_roles = ShopStoreRoles::getRolesDetailById($this->uid);
		$this->store_id  = $store_roles->store_id;
        $this->store = ShopStore::where(['id'=>$store_roles->store_id])->first();
        if($this->store->status==3){
            throw new ApiException('请等待审核');
        }
        if($this->store->status==5){
            throw new ApiException('您的账户已被冻结');
        }
        if($this->store->is_del==1){
            throw new ApiException('该账户已被删除');
        }
	}
}